package org.springframework.boot.web.practice.controller;

import org.springframework.boot.web.practice.dto.Welcome;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

/**
 * User: wujun
 * Date: 2014/7/17 14:59
 */
@RestController
public class IndexController {
    private static final String template = "你好!Welcome to Spring Boot. You are the %s visitor.";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping(value = {"", "index"}, produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<Welcome> index() {
        return new ResponseEntity<Welcome>(
                new Welcome(String.format(template, counter.incrementAndGet()))
                , HttpStatus.OK);
    }
}
